<?php
require_once APP  . '/application/admincontrollers/AdminAction.php';
require_once APP  . '/application/models/UserModel.php';

/**
 * ImageController 用户管理
 * 
 * @author RD / anthony
 * @version 
 */
    
class UserController extends AdminAction
{

	/**
     * initial function
     *
     */
    public function init()
    {
    	
    }
    
    /**
     * 显示图片列表
     *
     */
    public  function listAction()
    {
    	$nowp = $this->getParam ('nowp', 1);
        $per_page = 20;

        $image_obj = new UserModel($this->db);
        $result = $image_obj->fetchAll ($nowp, $per_page);

        $this->view->list = $result['list'];
        $this->view->page = $result['page'];
    }
    
    public  function searchAction()
    {
    	$email = $this->getParam("email");
    	$nowp = $this->getParam ('nowp', 1);
    	$per_page = 50;
    
    	$image_obj = new UserModel($this->db);
    	
    	if (empty($email)){
    		$result['list'] = array();
    	}else
    		$result = $image_obj->fetchByEmail ($email, $nowp, $per_page);
    
    	$this->view->list = $result['list'];
    	$this->view->page = $result['page'];
    }
    
    
    /**
     * 删除
     *
     */
    public function delAction()
    {
    	$this->setAutoRender(false);
    	
    	$UserId = $this->getPost("UserId");
    	
    	$result1 = $this->db->delete("user", "uid=" . $UserId, true);    	
    	echo 'T';
    }
    
    public function showAction()
    {
    	$UserId = $this->getParam("UserId");
    	$user = new UserModel($this->db);
    	
    	$this->view->content = $user->show($UserId);
    }
    
    public function resetAction()
    {
    	$this->setAutoRender(false);
    	global $cfg;
    	$UserId = $this->getPost("UserId");
    	
    	$user = new UserModel($this->db);
    	$pwd = md5(md5("123456") . $cfg['slot']);
    	$user->change($UserId, array("password" => $pwd));
    	echo 'T';
    }
}
